package com.ruoyi.business.service.impl;

import com.ruoyi.business.domain.SceneProcess;
import com.ruoyi.business.mapper.SceneProcessMapper;
import com.ruoyi.business.service.ISceneProcessService;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.core.utils.UniqueIdGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 场景流程Service业务层处理
 *
 * @author ruoyi
 * @date 2025-09-05
 */
@Service
public class SceneProcessServiceImpl implements ISceneProcessService
{
    @Autowired
    private SceneProcessMapper sceneProcessMapper;

    /**
     * 查询场景流程
     *
     * @param id 场景流程主键
     * @return 场景流程
     */
    @Override
    public SceneProcess selectSceneProcessById(Long id)
    {
        return sceneProcessMapper.selectSceneProcessById(id);
    }

    /**
     * 查询场景流程列表
     *
     * @param sceneProcess 场景流程
     * @return 场景流程
     */
    @Override
    public List<SceneProcess> selectSceneProcessList(SceneProcess sceneProcess)
    {
        return sceneProcessMapper.selectSceneProcessList(sceneProcess);
    }

    /**
     * 新增场景流程
     *
     * @param sceneProcess 场景流程
     * @return 结果
     */
    @Override
    public int insertSceneProcess(SceneProcess sceneProcess)
    {
        sceneProcess.setCreateTime(DateUtils.getNowDate());
        //自动产生流程编码，并保证唯一
        String code;
        SceneProcess searchSceneProcess = new SceneProcess();
        while (true) {
            code = UniqueIdGenerator.getUniqueClassName(10);
            searchSceneProcess.setSceneCode(code);
            List<SceneProcess> list = sceneProcessMapper.selectSceneProcessList(searchSceneProcess);
            if (list.size() == 0) {
                sceneProcess.setSceneCode(code);
                break;
            }
        }
        return sceneProcessMapper.insertSceneProcess(sceneProcess);
    }

    /**
     * 修改场景流程
     *
     * @param sceneProcess 场景流程
     * @return 结果
     */
    @Override
    public int updateSceneProcess(SceneProcess sceneProcess)
    {
        sceneProcess.setUpdateTime(DateUtils.getNowDate());
        return sceneProcessMapper.updateSceneProcess(sceneProcess);
    }

    /**
     * 批量删除场景流程
     *
     * @param ids 需要删除的场景流程主键
     * @return 结果
     */
    @Override
    public int deleteSceneProcessByIds(Long[] ids)
    {
        return sceneProcessMapper.deleteSceneProcessByIds(ids);
    }

    /**
     * 删除场景流程信息
     *
     * @param id 场景流程主键
     * @return 结果
     */
    @Override
    public int deleteSceneProcessById(Long id)
    {
        return sceneProcessMapper.deleteSceneProcessById(id);
    }
}
